package com.fengye.rabbit.login.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fengye.rabbit.login.domain.SysLog;
import com.fengye.rabbit.login.dto.UserLoginDTO;
import com.fengye.rabbit.login.mapper.SysLogMapper;
import com.fengye.rabbit.login.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 *
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog>
        implements SysLogService {

//    @Resource
//    SysLogMapper sysLogMapper;

    @Autowired
    ObjectMapper objectMapper;

    @Override
    public void recordLog(UserLoginDTO dto) throws JsonProcessingException {
        SysLog log = new SysLog();
        // log.setId(1);
        log.setUserId(dto.getUserId());
        log.setCreateTime(new Date());
        log.setMemo("用户登录");
        log.setModule("用户模块");
        log.setData(objectMapper.writeValueAsString(dto));

//        sysLogMapper.insert(log);
        this.save(log);
    }
}
